package com.hnevc.lizhimao;

import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.BaseAdapter;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class DiancanActivity extends AppCompatActivity {
    private String[] names ={"烤鸭","回锅肉","茄子","宫保鸡丁"};
    private String[] titles ={"烤鸭烤鸭烤鸭烤鸭烤鸭","回锅肉回锅肉回锅肉回锅肉回锅肉","茄子茄子茄子茄子茄子","宫保鸡丁宫保鸡丁宫保鸡丁宫保鸡丁"};
    private String[] prices ={"88元/一份","12.3元/一份","1.0元/一份","0.2元/一份"};
    private int[] icons={R.mipmap.one,R.mipmap.two,R.mipmap.tree,R.mipmap.four};
    private ListView mListView;

    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dingcan);
        mListView = findViewById(R.id.lv);
        MyBaseAdapter mAdapter = new MyBaseAdapter();
        mListView.setAdapter(mAdapter);
    }
    class MyBaseAdapter extends BaseAdapter{

        @Override
        public int getCount() {
            return titles.length;
        }

        @Override
        public Object getItem(int position) {
            return titles[position];
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View view =View.inflate(DiancanActivity.this,R.layout.dingcan1,null);
            ImageView iv = view.findViewById(R.id.image);
            TextView name =view.findViewById(R.id.name);
            TextView title =view.findViewById(R.id.name2);
            TextView price=view.findViewById(R.id.price);
            name.setText(names[position]);
            title.setText(titles[position]);
            price.setText(prices[position]);
            iv.setBackgroundResource(icons[position]);
            return view;
        }
    }
}
